home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / Doom / ADoom-0.8 / ADoom_src / am_map.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  31KB  |  1,376 lines

  1. // Emacs style mode select   -*- C++ -*- 
  2. //-----------------------------------------------------------------------------
  3. //
  4. // $Id:$
  5. //
  6. // Copyright (C) 1993-1996 by id Software, Inc.
  7. //
  8. // This source is available for distribution and/or modification
  9. // only under the terms of the DOOM Source Code License as
  10. // published by id Software. All rights reserved.
  11. //
  12. // The source is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
  15. // for more details.
  16. //
  17. //
  18. // $Log:$
  19. //
  20. // DESCRIPTION:  the automap code
  21. //
  22. //-----------------------------------------------------------------------------
  23.  
  24. static const char rcsid[] = "$Id: am_map.c,v 1.4 1997/02/03 21:24:33 b1 Exp $";
  25.  
  26. #include <stdio.h>
  27.  
  28.  
  29. #include "z_zone.h"
  30. #include "doomdef.h"
  31. #include "st_stuff.h"
  32. #include "p_local.h"
  33. #include "w_wad.h"
  34.  
  35. #include "m_cheat.h"
  36. #include "i_system.h"
  37.  
  38. // Needs access to LFB.
  39. #include "v_video.h"
  40.  
  41. // State.
  42. #include "doomstat.h"
  43. #include "r_state.h"
  44.  
  45. // Data.
  46. #include "dstrings.h"
  47.  
  48. #include "am_map.h"
  49.  
  50.  
  51. // For use if I do walls with outsides/insides
  52. #define REDS            (256-5*16)
  53. #define REDRANGE        16
  54. #define BLUES           (256-4*16+8)
  55. #define BLUERANGE       8
  56. #define GREENS          (7*16)
  57. #define GREENRANGE      16
  58. #define GRAYS           (6*16)
  59. #define GRAYSRANGE      16
  60. #define BROWNS          (4*16)
  61. #define BROWNRANGE      16
  62. #define YELLOWS         (256-32+7)
  63. #define YELLOWRANGE     1
  64. #define BLACK           0
  65. #define WHITE           (256-47)
  66.  
  67. // Automap colors
  68. #define BACKGROUND      BLACK
  69. #define YOURCOLORS      WHITE
  70. #define YOURRANGE       0
  71. #define WALLCOLORS      REDS
  72. #define WALLRANGE       REDRANGE
  73. #define TSWALLCOLORS    GRAYS
  74. #define TSWALLRANGE     GRAYSRANGE
  75. #define FDWALLCOLORS    BROWNS
  76. #define FDWALLRANGE     BROWNRANGE
  77. #define CDWALLCOLORS    YELLOWS
  78. #define CDWALLRANGE     YELLOWRANGE
  79. #define THINGCOLORS     GREENS
  80. #define THINGRANGE      GREENRANGE
  81. #define SECRETWALLCOLORS WALLCOLORS
  82. #define SECRETWALLRANGE WALLRANGE
  83. #define GRIDCOLORS      (GRAYS + GRAYSRANGE/2)
  84. #define GRIDRANGE       0
  85. #define XHAIRCOLORS     GRAYS
  86.  
  87. // drawing stuff
  88. #define FB              0
  89.  
  90. #define AM_PANDOWNKEY   KEY_DOWNARROW
  91. #define AM_PANUPKEY     KEY_UPARROW
  92. #define AM_PANRIGHTKEY  KEY_RIGHTARROW
  93. #define AM_PANLEFTKEY   KEY_LEFTARROW
  94. #define AM_ZOOMINKEY    '='
  95. #define AM_ZOOMOUTKEY   '-'
  96. #define AM_STARTKEY     KEY_TAB
  97. #define AM_ENDKEY       KEY_TAB
  98. #define AM_GOBIGKEY     '0'
  99. #define AM_FOLLOWKEY    'f'
  100. #define AM_GRIDKEY      'g'
  101. #define AM_MARKKEY      'm'
  102. #define AM_CLEARMARKKEY 'c'
  103.  
  104. #define AM_NUMMARKPOINTS 10
  105.  
  106. // scale on entry
  107. #define INITSCALEMTOF (.2*FRACUNIT)
  108. // how much the automap moves window per tic in frame-buffer coordinates
  109. // moves 140 pixels in 1 second
  110. #define F_PANINC        4
  111. // how much zoom-in per tic
  112. // goes to 2x in 1 second
  113. #define M_ZOOMIN        ((int) (1.02*FRACUNIT))
  114. // how much zoom-out per tic
  115. // pulls out to 0.5x in 1 second
  116. #define M_ZOOMOUT       ((int) (FRACUNIT/1.02))
  117.  
  118. // translates between frame-buffer and map distances
  119. #define FTOM(x) FixedMul(((x)<<16),scale_ftom)
  120. #define MTOF(x) (FixedMul((x),scale_mtof)>>16)
  121. // translates between frame-buffer and map coordinates
  122. #define CXMTOF(x)  (f_x + MTOF((x)-m_x))
  123. #define CYMTOF(y)  (f_y + (f_h - MTOF((y)-m_y)))
  124.  
  125. // the following is crap
  126. #define LINE_NEVERSEE ML_DONTDRAW
  127.  
  128. typedef struct
  129. {
  130.     int x, y;
  131. } fpoint_t;
  132.  
  133. typedef struct
  134. {
  135.     fpoint_t a, b;
  136. } fline_t;
  137.  
  138. typedef struct
  139. {
  140.     fixed_t             x,y;
  141. } mpoint_t;
  142.  
  143. typedef struct
  144. {
  145.     mpoint_t a, b;
  146. } mline_t;
  147.  
  148. typedef struct
  149. {
  150.     fixed_t slp, islp;
  151. } islope_t;
  152.  
  153.  
  154.  
  155. //
  156. // The vector graphics for the automap.
  157. //  A line drawing of the player pointing right,
  158. //   starting from the middle.
  159. //
  160. #define R ((8*PLAYERRADIUS)/7)
  161. mline_t player_arrow[] = {
  162.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  163.     { { R, 0 }, { R-R/2, R/4 } },  // ----->
  164.     { { R, 0 }, { R-R/2, -R/4 } },
  165.     { { -R+R/8, 0 }, { -R-R/8, R/4 } }, // >---->
  166.     { { -R+R/8, 0 }, { -R-R/8, -R/4 } },
  167.     { { -R+3*R/8, 0 }, { -R+R/8, R/4 } }, // >>--->
  168.     { { -R+3*R/8, 0 }, { -R+R/8, -R/4 } }
  169. };
  170. #undef R
  171. #define NUMPLYRLINES (sizeof(player_arrow)/sizeof(mline_t))
  172.  
  173. #define R ((8*PLAYERRADIUS)/7)
  174. mline_t cheat_player_arrow[] = {
  175.     { { -R+R/8, 0 }, { R, 0 } }, // -----
  176.     { { R, 0 }, { R-R/2, R/6 } },  // ----->
  177.     { { R, 0 }, { R-R/2, -R/6 } },
  178.     { { -R+R/8, 0 }, { -R-R/8, R/6 } }, // >----->
  179.     { { -R+R/8, 0 }, { -R-R/8, -R/6 } },
  180.     { { -R+3*R/8, 0 }, { -R+R/8, R/6 } }, // >>----->
  181.     { { -R+3*R/8, 0 }, { -R+R/8, -R/6 } },
  182.     { { -R/2, 0 }, { -R/2, -R/6 } }, // >>-d--->
  183.     { { -R/2, -R/6 }, { -R/2+R/6, -R/6 } },
  184.     { { -R/2+R/6, -R/6 }, { -R/2+R/6, R/4 } },
  185.     { { -R/6, 0 }, { -R/6, -R/6 } }, // >>-dd-->
  186.     { { -R/6, -R/6 }, { 0, -R/6 } },
  187.     { { 0, -R/6 }, { 0, R/4 } },
  188.     { { R/6, R/4 }, { R/6, -R/7 } }, // >>-ddt->
  189.     { { R/6, -R/7 }, { R/6+R/32, -R/7-R/32 } },
  190.     { { R/6+R/32, -R/7-R/32 }, { R/6+R/10, -R/7 } }
  191. };
  192. #undef R
  193. #define NUMCHEATPLYRLINES (sizeof(cheat_player_arrow)/sizeof(mline_t))
  194.  
  195. #define R (FRACUNIT)
  196. mline_t triangle_guy[] = {
  197.     { { -.867*R, -.5*R }, { .867*R, -.5*R } },
  198.     { { .867*R, -.5*R } , { 0, R } },
  199.     { { 0, R }, { -.867*R, -.5*R } }
  200. };
  201. #undef R
  202. #define NUMTRIANGLEGUYLINES (sizeof(triangle_guy)/sizeof(mline_t))
  203.  
  204. #define R (FRACUNIT)
  205. mline_t thintriangle_guy[] = {
  206.     { { -.5*R, -.7*R }, { R, 0 } },
  207.     { { R, 0 }, { -.5*R, .7*R } },
  208.     { { -.5*R, .7*R }, { -.5*R, -.7*R } }
  209. };
  210. #undef R
  211. #define NUMTHINTRIANGLEGUYLINES (sizeof(thintriangle_guy)/sizeof(mline_t))
  212.  
  213.  
  214.  
  215.  
  216. static int      cheating = 0;
  217. static int      grid = 0;
  218.  
  219. static int      leveljuststarted = 1;   // kluge until AM_LevelInit() is called
  220.  
  221. boolean         automapactive = false;
  222. static int      finit_width = SCREENWIDTH;
  223. static int      finit_height = SCREENHEIGHT - 32;
  224.  
  225. // location of window on screen
  226. static int      f_x;
  227. static int      f_y;
  228.  
  229. // size of window on screen
  230. static int      f_w;
  231. static int      f_h;
  232.  
  233. static int      lightlev;               // used for funky strobing effect
  234. static byte*    fb;                     // pseudo-frame buffer
  235. static int      amclock;
  236.  
  237. static mpoint_t m_paninc; // how far the window pans each tic (map coords)
  238. static fixed_t  mtof_zoommul; // how far the window zooms in each tic (map coords)
  239. static fixed_t  ftom_zoommul; // how far the window zooms in each tic (fb coords)
  240.  
  241. static fixed_t  m_x, m_y;   // LL x,y where the window is on the map (map coords)
  242. static fixed_t  m_x2, m_y2; // UR x,y where the window is on the map (map coords)
  243.  
  244. //
  245. // width/height of window on map (map coords)
  246. //
  247. static fixed_t  m_w;
  248. static fixed_t  m_h;
  249.  
  250. // based on level size
  251. static fixed_t  min_x;
  252. static fixed_t  min_y; 
  253. static fixed_t  max_x;
  254. static fixed_t  max_y;
  255.  
  256. static fixed_t  max_w; // max_x-min_x,
  257. static fixed_t  max_h; // max_y-min_y
  258.  
  259. // based on player size
  260. static fixed_t  min_w;
  261. static fixed_t  min_h;
  262.  
  263.  
  264. static fixed_t  min_scale_mtof; // used to tell when to stop zooming out
  265. static fixed_t  max_scale_mtof; // used to tell when to stop zooming in
  266.  
  267. // old stuff for recovery later
  268. static fixed_t old_m_w, old_m_h;
  269. static fixed_t old_m_x, old_m_y;
  270.  
  271. // old location used by the Follower routine
  272. static mpoint_t f_oldloc;
  273.  
  274. // used by MTOF to scale from map-to-frame-buffer coords
  275. static fixed_t scale_mtof = INITSCALEMTOF;
  276. // used by FTOM to scale from frame-buffer-to-map coords (=1/scale_mtof)
  277. static fixed_t scale_ftom;
  278.  
  279. static player_t *plr; // the player represented by an arrow
  280.  
  281. static patch_t *marknums[10]; // numbers used for marking by the automap
  282. static mpoint_t markpoints[AM_NUMMARKPOINTS]; // where the points are
  283. static int markpointnum = 0; // next point to be assigned
  284.  
  285. static int followplayer = 1; // specifies whether to follow the player around
  286.  
  287. static unsigned char cheat_amap_seq[] = { 0xb2, 0x26, 0x26, 0x2e, 0xff };
  288. static cheatseq_t cheat_amap = { cheat_amap_seq, 0 };
  289.  
  290. static boolean stopped = true;
  291.  
  292. extern boolean viewactive;
  293. extern boolean rotatemap;
  294. extern boolean maponhu;
  295. //extern byte screens[][SCREENWIDTH*SCREENHEIGHT];
  296.  
  297.  
  298.  
  299. void
  300. V_MarkRect
  301. ( int   x,
  302.   int   y,
  303.   int   width,
  304.   int   height );
  305.  
  306. // Calculates the slope and slope according to the x-axis of a line
  307. // segment in map coordinates (with the upright y-axis n' all) so
  308. // that it can be used with the brain-dead drawing stuff.
  309.  
  310. void
  311. AM_getIslope
  312. ( mline_t*      ml,
  313.   islope_t*     is )
  314. {
  315.     int dx, dy;
  316.  
  317.     dy = ml->a.y - ml->b.y;
  318.     dx = ml->b.x - ml->a.x;
  319.     if (!dy) is->islp = (dx<0?-MAXINT:MAXINT);
  320.     else is->islp = FixedDiv(dx, dy);
  321.     if (!dx) is->slp = (dy<0?-MAXINT:MAXINT);
  322.     else is->slp = FixedDiv(dy, dx);
  323.  
  324. }
  325.  
  326. //
  327. //
  328. //
  329. void AM_activateNewScale(void)
  330. {
  331.     m_x += m_w/2;
  332.     m_y += m_h/2;
  333.     m_w = FTOM(f_w);
  334.     m_h = FTOM(f_h);
  335.     m_x -= m_w/2;
  336.     m_y -= m_h/2;
  337.     m_x2 = m_x + m_w;
  338.     m_y2 = m_y + m_h;
  339. }
  340.  
  341. //
  342. //
  343. //
  344. void AM_saveScaleAndLoc(void)
  345. {
  346.     old_m_x = m_x;
  347.     old_m_y = m_y;
  348.     old_m_w = m_w;
  349.     old_m_h = m_h;
  350. }
  351.  
  352. //
  353. //
  354. //
  355. void AM_restoreScaleAndLoc(void)
  356. {
  357.  
  358.     m_w = old_m_w;
  359.     m_h = old_m_h;
  360.     if (!followplayer)
  361.     {
  362.         m_x = old_m_x;
  363.         m_y = old_m_y;
  364.     } else {
  365.         m_x = plr->mo->x - m_w/2;
  366.         m_y = plr->mo->y - m_h/2;
  367.     }
  368.     m_x2 = m_x + m_w;
  369.     m_y2 = m_y + m_h;
  370.  
  371.     // Change the scaling multipliers
  372.     scale_mtof = FixedDiv(f_w<<FRACBITS, m_w);
  373.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  374. }
  375.  
  376. //
  377. // adds a marker at the current location
  378. //
  379. void AM_addMark(void)
  380. {
  381.     markpoints[markpointnum].x = m_x + m_w/2;
  382.     markpoints[markpointnum].y = m_y + m_h/2;
  383.     markpointnum = (markpointnum + 1) % AM_NUMMARKPOINTS;
  384.  
  385. }
  386.  
  387. //
  388. // Determines bounding box of all vertices,
  389. // sets global variables controlling zoom range.
  390. //
  391. void AM_findMinMaxBoundaries(void)
  392. {
  393.     int i;
  394.     fixed_t a;
  395.     fixed_t b;
  396.  
  397.     min_x = min_y =  MAXINT;
  398.     max_x = max_y = -MAXINT;
  399.   
  400.     for (i=0;i<numvertexes;i++)
  401.     {
  402.         if (vertexes[i].x < min_x)
  403.             min_x = vertexes[i].x;
  404.         else if (vertexes[i].x > max_x)
  405.             max_x = vertexes[i].x;
  406.     
  407.         if (vertexes[i].y < min_y)
  408.             min_y = vertexes[i].y;
  409.         else if (vertexes[i].y > max_y)
  410.             max_y = vertexes[i].y;
  411.     }
  412.   
  413.     max_w = max_x - min_x;
  414.     max_h = max_y - min_y;
  415.  
  416.     min_w = 2*PLAYERRADIUS; // const? never changed?
  417.     min_h = 2*PLAYERRADIUS;
  418.  
  419.     a = FixedDiv(f_w<<FRACBITS, max_w);
  420.     b = FixedDiv(f_h<<FRACBITS, max_h);
  421.   
  422.     min_scale_mtof = a < b ? a : b;
  423.     max_scale_mtof = FixedDiv(f_h<<FRACBITS, 2*PLAYERRADIUS);
  424.  
  425. }
  426.  
  427.  
  428. //
  429. //
  430. //
  431. void AM_changeWindowLoc(void)
  432. {
  433.     if (m_paninc.x || m_paninc.y)
  434.     {
  435.         followplayer = 0;
  436.         f_oldloc.x = MAXINT;
  437.     }
  438.  
  439.     m_x += m_paninc.x;
  440.     m_y += m_paninc.y;
  441.  
  442.     if (m_x + m_w/2 > max_x)
  443.         m_x = max_x - m_w/2;
  444.     else if (m_x + m_w/2 < min_x)
  445.         m_x = min_x - m_w/2;
  446.   
  447.     if (m_y + m_h/2 > max_y)
  448.         m_y = max_y - m_h/2;
  449.     else if (m_y + m_h/2 < min_y)
  450.         m_y = min_y - m_h/2;
  451.  
  452.     m_x2 = m_x + m_w;
  453.     m_y2 = m_y + m_h;
  454. }
  455.  
  456.  
  457. //
  458. //
  459. //
  460. void AM_initVariables(void)
  461. {
  462.     int pnum;
  463.     static event_t st_notify = { ev_keyup, AM_MSGENTERED };
  464.  
  465.     automapactive = true;
  466.     fb = screens[0];
  467.  
  468.     f_oldloc.x = MAXINT;
  469.     amclock = 0;
  470.     lightlev = 0;
  471.  
  472.     m_paninc.x = m_paninc.y = 0;
  473.     ftom_zoommul = FRACUNIT;
  474.     mtof_zoommul = FRACUNIT;
  475.  
  476.     m_w = FTOM(f_w);
  477.     m_h = FTOM(f_h);
  478.  
  479.     // find player to center on initially
  480.     if (!playeringame[pnum = consoleplayer])
  481.         for (pnum=0;pnum<MAXPLAYERS;pnum++)
  482.             if (playeringame[pnum])
  483.                 break;
  484.   
  485.     plr = &players[pnum];
  486.     m_x = plr->mo->x - m_w/2;
  487.     m_y = plr->mo->y - m_h/2;
  488.     AM_changeWindowLoc();
  489.  
  490.     // for saving & restoring
  491.     old_m_x = m_x;
  492.     old_m_y = m_y;
  493.     old_m_w = m_w;
  494.     old_m_h = m_h;
  495.  
  496.     // inform the status bar of the change
  497.     ST_Responder(&st_notify);
  498.  
  499. }
  500.  
  501. //
  502. // 
  503. //
  504. void AM_loadPics(void)
  505. {
  506.     int i;
  507.     char namebuf[9];
  508.   
  509.     for (i=0;i<10;i++)
  510.     {
  511.         sprintf(namebuf, "AMMNUM%d", i);
  512.         marknums[i] = W_CacheLumpName(namebuf, PU_STATIC);
  513.     }
  514.  
  515. }
  516.  
  517. void AM_unloadPics(void)
  518. {
  519.     int i;
  520.   
  521.     for (i=0;i<10;i++)
  522.         Z_ChangeTag(marknums[i], PU_CACHE);
  523.  
  524. }
  525.  
  526. void AM_clearMarks(void)
  527. {
  528.     int i;
  529.  
  530.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  531.         markpoints[i].x = -1; // means empty
  532.     markpointnum = 0;
  533. }
  534.  
  535. //
  536. // should be called at the start of every level
  537. // right now, i figure it out myself
  538. //
  539. void AM_LevelInit(void)
  540. {
  541.     leveljuststarted = 0;
  542.  
  543.     f_x = f_y = 0;
  544.     f_w = finit_width;
  545.     f_h = finit_height;
  546.  
  547.     AM_clearMarks();
  548.  
  549.     AM_findMinMaxBoundaries();
  550.     scale_mtof = FixedDiv(min_scale_mtof, (int) (0.7*FRACUNIT));
  551.     if (scale_mtof > max_scale_mtof)
  552.         scale_mtof = min_scale_mtof;
  553.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  554. }
  555.  
  556.  
  557.  
  558.  
  559. //
  560. //
  561. //
  562. void AM_Stop (void)
  563. {
  564.     static event_t st_notify = { 0, ev_keyup, AM_MSGEXITED };
  565.  
  566.     AM_unloadPics();
  567.     automapactive = false;
  568.     ST_Responder(&st_notify);
  569.     stopped = true;
  570. }
  571.  
  572. //
  573. //
  574. //
  575. void AM_Start (void)
  576. {
  577.     static int lastlevel = -1, lastepisode = -1;
  578.  
  579.     if (!stopped) AM_Stop();
  580.     stopped = false;
  581.     if (lastlevel != gamemap || lastepisode != gameepisode)
  582.     {
  583.         AM_LevelInit();
  584.         lastlevel = gamemap;
  585.         lastepisode = gameepisode;
  586.     }
  587.     AM_initVariables();
  588.     AM_loadPics();
  589. }
  590.  
  591. //
  592. // set the window scale to the maximum size
  593. //
  594. void AM_minOutWindowScale(void)
  595. {
  596.     scale_mtof = min_scale_mtof;
  597.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  598.     AM_activateNewScale();
  599. }
  600.  
  601. //
  602. // set the window scale to the minimum size
  603. //
  604. void AM_maxOutWindowScale(void)
  605. {
  606.     scale_mtof = max_scale_mtof;
  607.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  608.     AM_activateNewScale();
  609. }
  610.  
  611.  
  612. //
  613. // Handle events (user inputs) in automap mode
  614. //
  615. boolean
  616. AM_Responder
  617. ( event_t*      ev )
  618. {
  619.  
  620.     int rc;
  621.     static int cheatstate=0;
  622.     static int bigstate=0;
  623.     static char buffer[20];
  624.  
  625.     rc = false;
  626.  
  627.     if (!automapactive)
  628.     {
  629.         if (ev->type == ev_keydown && ev->data1 == AM_STARTKEY)
  630.         {
  631.             AM_Start ();
  632.             viewactive = false;
  633.             rc = true;
  634.         }
  635.     }
  636.  
  637.     else if (ev->type == ev_keydown)
  638.     {
  639.  
  640.         rc = true;
  641.         switch(ev->data1)
  642.         {
  643.           case AM_PANRIGHTKEY: // pan right
  644.             if (!followplayer) m_paninc.x = FTOM(F_PANINC);
  645.             else rc = false;
  646.             break;
  647.           case AM_PANLEFTKEY: // pan left
  648.             if (!followplayer) m_paninc.x = -FTOM(F_PANINC);
  649.             else rc = false;
  650.             break;
  651.           case AM_PANUPKEY: // pan up
  652.             if (!followplayer) m_paninc.y = FTOM(F_PANINC);
  653.             else rc = false;
  654.             break;
  655.           case AM_PANDOWNKEY: // pan down
  656.             if (!followplayer) m_paninc.y = -FTOM(F_PANINC);
  657.             else rc = false;
  658.             break;
  659.           case AM_ZOOMOUTKEY: // zoom out
  660.             mtof_zoommul = M_ZOOMOUT;
  661.             ftom_zoommul = M_ZOOMIN;
  662.             break;
  663.           case AM_ZOOMINKEY: // zoom in
  664.             mtof_zoommul = M_ZOOMIN;
  665.             ftom_zoommul = M_ZOOMOUT;
  666.             break;
  667.           case AM_ENDKEY:
  668.             bigstate = 0;
  669.             viewactive = true;
  670.             AM_Stop ();
  671.             break;
  672.           case AM_GOBIGKEY:
  673.             bigstate = !bigstate;
  674.             if (bigstate)
  675.             {
  676.                 AM_saveScaleAndLoc();
  677.                 AM_minOutWindowScale();
  678.             }
  679.             else AM_restoreScaleAndLoc();
  680.             break;
  681.           case AM_FOLLOWKEY:
  682.             followplayer = !followplayer;
  683.             f_oldloc.x = MAXINT;
  684.             plr->message = followplayer ? AMSTR_FOLLOWON : AMSTR_FOLLOWOFF;
  685.             break;
  686.           case AM_GRIDKEY:
  687.             grid = !grid;
  688.             plr->message = grid ? AMSTR_GRIDON : AMSTR_GRIDOFF;
  689.             break;
  690.           case AM_MARKKEY:
  691.             sprintf(buffer, "%s %d", AMSTR_MARKEDSPOT, markpointnum);
  692.             plr->message = buffer;
  693.             AM_addMark();
  694.             break;
  695.           case AM_CLEARMARKKEY:
  696.             AM_clearMarks();
  697.             plr->message = AMSTR_MARKSCLEARED;
  698.             break;
  699.           default:
  700.             cheatstate=0;
  701.             rc = false;
  702.         }
  703.         if (!deathmatch && cht_CheckCheat(&cheat_amap, ev->data1))
  704.         {
  705.             rc = false;
  706.             cheating = (cheating+1) % 3;
  707.         }
  708.     }
  709.  
  710.     else if (ev->type == ev_keyup)
  711.     {
  712.         rc = false;
  713.         switch (ev->data1)
  714.         {
  715.           case AM_PANRIGHTKEY:
  716.             if (!followplayer) m_paninc.x = 0;
  717.             break;
  718.           case AM_PANLEFTKEY:
  719.             if (!followplayer) m_paninc.x = 0;
  720.             break;
  721.           case AM_PANUPKEY:
  722.             if (!followplayer) m_paninc.y = 0;
  723.             break;
  724.           case AM_PANDOWNKEY:
  725.             if (!followplayer) m_paninc.y = 0;
  726.             break;
  727.           case AM_ZOOMOUTKEY:
  728.           case AM_ZOOMINKEY:
  729.             mtof_zoommul = FRACUNIT;
  730.             ftom_zoommul = FRACUNIT;
  731.             break;
  732.         }
  733.     }
  734.  
  735.     return rc;
  736.  
  737. }
  738.  
  739.  
  740. //
  741. // Zooming
  742. //
  743. void AM_changeWindowScale(void)
  744. {
  745.  
  746.     // Change the scaling multipliers
  747.     scale_mtof = FixedMul(scale_mtof, mtof_zoommul);
  748.     scale_ftom = FixedDiv(FRACUNIT, scale_mtof);
  749.  
  750.     if (scale_mtof < min_scale_mtof)
  751.         AM_minOutWindowScale();
  752.     else if (scale_mtof > max_scale_mtof)
  753.         AM_maxOutWindowScale();
  754.     else
  755.         AM_activateNewScale();
  756. }
  757.  
  758.  
  759. //
  760. //
  761. //
  762. void AM_doFollowPlayer(void)
  763. {
  764.  
  765.     if (f_oldloc.x != plr->mo->x || f_oldloc.y != plr->mo->y)
  766.     {
  767.         m_x = FTOM(MTOF(plr->mo->x)) - m_w/2;
  768.         m_y = FTOM(MTOF(plr->mo->y)) - m_h/2;
  769.         m_x2 = m_x + m_w;
  770.         m_y2 = m_y + m_h;
  771.         f_oldloc.x = plr->mo->x;
  772.         f_oldloc.y = plr->mo->y;
  773.  
  774.         //  m_x = FTOM(MTOF(plr->mo->x - m_w/2));
  775.         //  m_y = FTOM(MTOF(plr->mo->y - m_h/2));
  776.         //  m_x = plr->mo->x - m_w/2;
  777.         //  m_y = plr->mo->y - m_h/2;
  778.  
  779.     }
  780.  
  781. }
  782.  
  783. //
  784. //
  785. //
  786. void AM_updateLightLev(void)
  787. {
  788.     static nexttic = 0;
  789.     //static int litelevels[] = { 0, 3, 5, 6, 6, 7, 7, 7 };
  790.     static int litelevels[] = { 0, 4, 7, 10, 12, 14, 15, 15 };
  791.     static int litelevelscnt = 0;
  792.    
  793.     // Change light level
  794.     if (amclock>nexttic)
  795.     {
  796.         lightlev = litelevels[litelevelscnt++];
  797.         if (litelevelscnt == sizeof(litelevels)/sizeof(int)) litelevelscnt = 0;
  798.         nexttic = amclock + 6 - (amclock % 6);
  799.     }
  800.  
  801. }
  802.  
  803.  
  804. //
  805. // Updates on Game Tick
  806. //
  807. void AM_Ticker (void)
  808. {
  809.  
  810.     if (!automapactive)
  811.         return;
  812.  
  813.     amclock++;
  814.  
  815.     if (followplayer)
  816.         AM_doFollowPlayer();
  817.  
  818.     // Change the zoom if necessary
  819.     if (ftom_zoommul != FRACUNIT)
  820.         AM_changeWindowScale();
  821.  
  822.     // Change x,y location
  823.     if (m_paninc.x || m_paninc.y)
  824.         AM_changeWindowLoc();
  825.  
  826.     // Update light level
  827.     // AM_updateLightLev();
  828.  
  829. }
  830.  
  831.  
  832. //
  833. // Clear automap frame buffer.
  834. //
  835. void AM_clearFB(int color)
  836. {
  837.     memset(fb, color, f_w*f_h);
  838. }
  839.  
  840.  
  841. //
  842. // Automap clipping of lines.
  843. //
  844. // Based on Cohen-Sutherland clipping algorithm but with a slightly
  845. // faster reject and precalculated slopes.  If the speed is needed,
  846. // use a hash algorithm to handle  the common cases.
  847. //
  848. boolean
  849. AM_clipMline
  850. ( mline_t*      ml,
  851.   fline_t*      fl )
  852. {
  853.     enum
  854.     {
  855.         LEFT    =1,
  856.         RIGHT   =2,
  857.         BOTTOM  =4,
  858.         TOP     =8
  859.     };
  860.     
  861.     register    outcode1 = 0;
  862.     register    outcode2 = 0;
  863.     register    outside;
  864.     
  865.     fpoint_t    tmp;
  866.     int         dx;
  867.     int         dy;
  868.  
  869.     
  870. #define DOOUTCODE(oc, mx, my) \
  871.     (oc) = 0; \
  872.     if ((my) < 0) (oc) |= TOP; \
  873.     else if ((my) >= f_h) (oc) |= BOTTOM; \
  874.     if ((mx) < 0) (oc) |= LEFT; \
  875.     else if ((mx) >= f_w) (oc) |= RIGHT;
  876.  
  877.     
  878.     // do trivial rejects and outcodes
  879.     if (ml->a.y > m_y2)
  880.         outcode1 = TOP;
  881.     else if (ml->a.y < m_y)
  882.         outcode1 = BOTTOM;
  883.  
  884.     if (ml->b.y > m_y2)
  885.         outcode2 = TOP;
  886.     else if (ml->b.y < m_y)
  887.         outcode2 = BOTTOM;
  888.     
  889.     if (outcode1 & outcode2)
  890.         return false; // trivially outside
  891.  
  892.     if (ml->a.x < m_x)
  893.         outcode1 |= LEFT;
  894.     else if (ml->a.x > m_x2)
  895.         outcode1 |= RIGHT;
  896.     
  897.     if (ml->b.x < m_x)
  898.         outcode2 |= LEFT;
  899.     else if (ml->b.x > m_x2)
  900.         outcode2 |= RIGHT;
  901.     
  902.     if (outcode1 & outcode2)
  903.         return false; // trivially outside
  904.  
  905.     // transform to frame-buffer coordinates.
  906.     fl->a.x = CXMTOF(ml->a.x);
  907.     fl->a.y = CYMTOF(ml->a.y);
  908.     fl->b.x = CXMTOF(ml->b.x);
  909.     fl->b.y = CYMTOF(ml->b.y);
  910.  
  911.     DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  912.     DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  913.  
  914.     if (outcode1 & outcode2)
  915.         return false;
  916.  
  917.     while (outcode1 | outcode2)
  918.     {
  919.         // may be partially inside box
  920.         // find an outside point
  921.         if (outcode1)
  922.             outside = outcode1;
  923.         else
  924.             outside = outcode2;
  925.         
  926.         // clip to each side
  927.         if (outside & TOP)
  928.         {
  929.             dy = fl->a.y - fl->b.y;
  930.             dx = fl->b.x - fl->a.x;
  931.             tmp.x = fl->a.x + (dx*(fl->a.y))/dy;
  932.             tmp.y = 0;
  933.         }
  934.         else if (outside & BOTTOM)
  935.         {
  936.             dy = fl->a.y - fl->b.y;
  937.             dx = fl->b.x - fl->a.x;
  938.             tmp.x = fl->a.x + (dx*(fl->a.y-f_h))/dy;
  939.             tmp.y = f_h-1;
  940.         }
  941.         else if (outside & RIGHT)
  942.         {
  943.             dy = fl->b.y - fl->a.y;
  944.             dx = fl->b.x - fl->a.x;
  945.             tmp.y = fl->a.y + (dy*(f_w-1 - fl->a.x))/dx;
  946.             tmp.x = f_w-1;
  947.         }
  948.         else if (outside & LEFT)
  949.         {
  950.             dy = fl->b.y - fl->a.y;
  951.             dx = fl->b.x - fl->a.x;
  952.             tmp.y = fl->a.y + (dy*(-fl->a.x))/dx;
  953.             tmp.x = 0;
  954.         }
  955.  
  956.         if (outside == outcode1)
  957.         {
  958.             fl->a = tmp;
  959.             DOOUTCODE(outcode1, fl->a.x, fl->a.y);
  960.         }
  961.         else
  962.         {
  963.             fl->b = tmp;
  964.             DOOUTCODE(outcode2, fl->b.x, fl->b.y);
  965.         }
  966.         
  967.         if (outcode1 & outcode2)
  968.             return false; // trivially outside
  969.     }
  970.  
  971.     return true;
  972. }
  973. #undef DOOUTCODE
  974.  
  975.  
  976. //
  977. // Classic Bresenham w/ whatever optimizations needed for speed
  978. //
  979. void
  980. AM_drawFline
  981. ( fline_t*      fl,
  982.   int           color )
  983. {
  984.     register int x;
  985.     register int y;
  986.     register int dx;
  987.     register int dy;
  988.     register int sx;
  989.     register int sy;
  990.     register int ax;
  991.     register int ay;
  992.     register int d;
  993. /*    
  994.     static fuck = 0;
  995.  
  996.     // For debugging only
  997.  
  998.     if (      fl->a.x < 0 || fl->a.x >= f_w
  999.            || fl->a.y < 0 || fl->a.y >= f_h
  1000.            || fl->b.x < 0 || fl->b.x >= f_w
  1001.            || fl->b.y < 0 || fl->b.y >= f_h)
  1002.     {
  1003.         fprintf(stderr, "fuck %d \r", fuck++);
  1004.         return;
  1005.     }
  1006. */
  1007.  
  1008. #define PUTDOT(xx,yy,cc) fb[(yy)*f_w+(xx)]=(cc)
  1009.  
  1010.     dx = fl->b.x - fl->a.x;
  1011.     ax = 2 * (dx<0 ? -dx : dx);
  1012.     sx = dx<0 ? -1 : 1;
  1013.  
  1014.     dy = fl->b.y - fl->a.y;
  1015.     ay = 2 * (dy<0 ? -dy : dy);
  1016.     sy = dy<0 ? -1 : 1;
  1017.  
  1018.     x = fl->a.x;
  1019.     y = fl->a.y;
  1020.  
  1021.     if (ax > ay)
  1022.     {
  1023.         d = ay - ax/2;
  1024.         while (1)
  1025.         {
  1026.             PUTDOT(x,y,color);
  1027.             if (x == fl->b.x) return;
  1028.             if (d>=0)
  1029.             {
  1030.                 y += sy;
  1031.                 d -= ax;
  1032.             }
  1033.             x += sx;
  1034.             d += ay;
  1035.         }
  1036.     }
  1037.     else
  1038.     {
  1039.         d = ax - ay/2;
  1040.         while (1)
  1041.         {
  1042.             PUTDOT(x, y, color);
  1043.             if (y == fl->b.y) return;
  1044.             if (d >= 0)
  1045.             {
  1046.                 x += sx;
  1047.                 d -= ay;
  1048.             }
  1049.             y += sy;
  1050.             d += ax;
  1051.         }
  1052.     }
  1053. }
  1054.  
  1055. //
  1056. // Rotation in 2D.
  1057. // Used to rotate player arrow line character.
  1058. //
  1059. void
  1060. AM_rotate
  1061. ( fixed_t*      x,
  1062.   fixed_t*      y,
  1063.   angle_t       a )
  1064. {
  1065.     fixed_t tmpx;
  1066.  
  1067.     tmpx =
  1068.         FixedMul(*x,finecosine[a>>ANGLETOFINESHIFT])
  1069.         - FixedMul(*y,finesine[a>>ANGLETOFINESHIFT]);
  1070.     
  1071.     *y   =
  1072.         FixedMul(*x,finesine[a>>ANGLETOFINESHIFT])
  1073.         + FixedMul(*y,finecosine[a>>ANGLETOFINESHIFT]);
  1074.  
  1075.     *x = tmpx;
  1076. }
  1077.  
  1078.  
  1079. //
  1080. // Clip lines, draw visible part sof lines.
  1081. //
  1082. void
  1083. AM_drawMline
  1084. ( mline_t*      ml,
  1085.   int           color )
  1086. {
  1087.     static fline_t fl;
  1088.     mline_t     l;
  1089.  
  1090.     /* Rotate Map Patch - CDE 98' */
  1091.     if(rotatemap) {
  1092.         l.a.x = ml->a.x-plr->mo->x;
  1093.         l.a.y = ml->a.y-plr->mo->y;
  1094.         l.b.x = ml->b.x-plr->mo->x;
  1095.         l.b.y = ml->b.y-plr->mo->y;
  1096.  
  1097.         AM_rotate(&l.a.x, &l.a.y, ANG90-plr->mo->angle);
  1098.         AM_rotate(&l.b.x, &l.b.y, ANG90-plr->mo->angle);
  1099.  
  1100.         l.a.x += plr->mo->x;
  1101.         l.a.y += plr->mo->y;
  1102.         l.b.x += plr->mo->x;
  1103.         l.b.y += plr->mo->y;
  1104.  
  1105.         if (AM_clipMline(&l, &fl))
  1106.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1107.     } else {
  1108.         if (AM_clipMline(ml, &fl))
  1109.             AM_drawFline(&fl, color); // draws it on frame buffer using fb coords
  1110.     }
  1111. }
  1112.  
  1113.  
  1114.  
  1115. //
  1116. // Draws flat (floor/ceiling tile) aligned grid lines.
  1117. //
  1118. void AM_drawGrid(int color)
  1119. {
  1120.     fixed_t x, y;
  1121.     fixed_t start, end;
  1122.     mline_t ml;
  1123.  
  1124.     // Figure out start of vertical gridlines
  1125.     start = m_x;
  1126.     if ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS))
  1127.         start += (MAPBLOCKUNITS<<FRACBITS)
  1128.             - ((start-bmaporgx)%(MAPBLOCKUNITS<<FRACBITS));
  1129.     end = m_x + m_w;
  1130.  
  1131.     // draw vertical gridlines
  1132.     ml.a.y = m_y;
  1133.     ml.b.y = m_y+m_h;
  1134.     for (x=start; x<end; x+=(MAPBLOCKUNITS<<FRACBITS))
  1135.     {
  1136.         ml.a.x = x;
  1137.         ml.b.x = x;
  1138.         AM_drawMline(&ml, color);
  1139.     }
  1140.  
  1141.     // Figure out start of horizontal gridlines
  1142.     start = m_y;
  1143.     if ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS))
  1144.         start += (MAPBLOCKUNITS<<FRACBITS)
  1145.             - ((start-bmaporgy)%(MAPBLOCKUNITS<<FRACBITS));
  1146.     end = m_y + m_h;
  1147.  
  1148.     // draw horizontal gridlines
  1149.     ml.a.x = m_x;
  1150.     ml.b.x = m_x + m_w;
  1151.     for (y=start; y<end; y+=(MAPBLOCKUNITS<<FRACBITS))
  1152.     {
  1153.         ml.a.y = y;
  1154.         ml.b.y = y;
  1155.         AM_drawMline(&ml, color);
  1156.     }
  1157.  
  1158. }
  1159.  
  1160. //
  1161. // Determines visible lines, draws them.
  1162. // This is LineDef based, not LineSeg based.
  1163. //
  1164. void AM_drawWalls(void)
  1165. {
  1166.     int i;
  1167.     static mline_t l;
  1168.  
  1169.     for (i=0;i<numlines;i++)
  1170.     {
  1171.         l.a.x = lines[i].v1->x;
  1172.         l.a.y = lines[i].v1->y;
  1173.         l.b.x = lines[i].v2->x;
  1174.         l.b.y = lines[i].v2->y;
  1175.         if (cheating || (lines[i].flags & ML_MAPPED))
  1176.         {
  1177.             if ((lines[i].flags & LINE_NEVERSEE) && !cheating)
  1178.                 continue;
  1179.             if (!lines[i].backsector)
  1180.             {
  1181.                 AM_drawMline(&l, WALLCOLORS+lightlev);
  1182.             }
  1183.             else
  1184.             {
  1185.                 if (lines[i].special == 39)
  1186.                 { // teleporters
  1187.                     AM_drawMline(&l, WALLCOLORS+WALLRANGE/2);
  1188.                 }
  1189.                 else if (lines[i].flags & ML_SECRET) // secret door
  1190.                 {
  1191.                     if (cheating) AM_drawMline(&l, SECRETWALLCOLORS + lightlev);
  1192.                     else AM_drawMline(&l, WALLCOLORS+lightlev);
  1193.                 }
  1194.                 else if (lines[i].backsector->floorheight
  1195.                            != lines[i].frontsector->floorheight) {
  1196.                     AM_drawMline(&l, FDWALLCOLORS + lightlev); // floor level change
  1197.                 }
  1198.                 else if (lines[i].backsector->ceilingheight
  1199.                            != lines[i].frontsector->ceilingheight) {
  1200.                     AM_drawMline(&l, CDWALLCOLORS+lightlev); // ceiling level change
  1201.                 }
  1202.                 else if (cheating) {
  1203.                     AM_drawMline(&l, TSWALLCOLORS+lightlev);
  1204.                 }
  1205.             }
  1206.         }
  1207.         else if (plr->powers[pw_allmap])
  1208.         {
  1209.             if (!(lines[i].flags & LINE_NEVERSEE)) AM_drawMline(&l, GRAYS+3);
  1210.         }
  1211.     }
  1212. }
  1213.  
  1214. void
  1215. AM_drawLineCharacter
  1216. ( mline_t*      lineguy,
  1217.   int           lineguylines,
  1218.   fixed_t       scale,
  1219.   angle_t       angle,
  1220.   int           color,
  1221.   fixed_t       x,
  1222.   fixed_t       y )
  1223. {
  1224.     int         i;
  1225.     mline_t     l;
  1226.  
  1227.     for (i=0;i<lineguylines;i++)
  1228.     {
  1229.         l.a.x = lineguy[i].a.x;
  1230.         l.a.y = lineguy[i].a.y;
  1231.  
  1232.         if (scale)
  1233.         {
  1234.             l.a.x = FixedMul(scale, l.a.x);
  1235.             l.a.y = FixedMul(scale, l.a.y);
  1236.         }
  1237.  
  1238.         if (angle)
  1239.             AM_rotate(&l.a.x, &l.a.y, angle);
  1240.  
  1241.         l.a.x += x;
  1242.         l.a.y += y;
  1243.  
  1244.         l.b.x = lineguy[i].b.x;
  1245.         l.b.y = lineguy[i].b.y;
  1246.  
  1247.         if (scale)
  1248.         {
  1249.             l.b.x = FixedMul(scale, l.b.x);
  1250.             l.b.y = FixedMul(scale, l.b.y);
  1251.         }
  1252.  
  1253.         if (angle)
  1254.             AM_rotate(&l.b.x, &l.b.y, angle);
  1255.         
  1256.         l.b.x += x;
  1257.         l.b.y += y;
  1258.  
  1259.         AM_drawMline(&l, color);
  1260.     }
  1261. }
  1262.  
  1263. void AM_drawPlayers(void)
  1264. {
  1265.     int         i;
  1266.     player_t*   p;
  1267.     static int  their_colors[] = { GREENS, GRAYS, BROWNS, REDS };
  1268.     int         their_color = -1;
  1269.     int         color;
  1270.  
  1271.     if (!netgame)
  1272.     {
  1273.         if (cheating)
  1274.             AM_drawLineCharacter
  1275.                 (cheat_player_arrow, NUMCHEATPLYRLINES, 0,
  1276.                  plr->mo->angle, WHITE, plr->mo->x, plr->mo->y);
  1277.         else
  1278.             AM_drawLineCharacter
  1279.                 (player_arrow, NUMPLYRLINES, 0, plr->mo->angle,
  1280.                  WHITE, plr->mo->x, plr->mo->y);
  1281.         return;
  1282.     }
  1283.  
  1284.     for (i=0;i<MAXPLAYERS;i++)
  1285.     {
  1286.         their_color++;
  1287.         p = &players[i];
  1288.  
  1289.         if ( (deathmatch && !singledemo) && p != plr)
  1290.             continue;
  1291.  
  1292.         if (!playeringame[i])
  1293.             continue;
  1294.  
  1295.         if (p->powers[pw_invisibility])
  1296.             color = 246; // *close* to black
  1297.         else
  1298.             color = their_colors[their_color];
  1299.         
  1300.         AM_drawLineCharacter
  1301.             (player_arrow, NUMPLYRLINES, 0, p->mo->angle,
  1302.              color, p->mo->x, p->mo->y);
  1303.     }
  1304.  
  1305. }
  1306.  
  1307. void
  1308. AM_drawThings
  1309. ( int   colors,
  1310.   int   colorrange)
  1311. {
  1312.     int         i;
  1313.     mobj_t*     t;
  1314.  
  1315.     for (i=0;i<numsectors;i++)
  1316.     {
  1317.         t = sectors[i].thinglist;
  1318.         while (t)
  1319.         {
  1320.             AM_drawLineCharacter
  1321.                 (thintriangle_guy, NUMTHINTRIANGLEGUYLINES,
  1322.                  16<<FRACBITS, t->angle, colors+lightlev, t->x, t->y);
  1323.             t = t->snext;
  1324.         }
  1325.     }
  1326. }
  1327.  
  1328. void AM_drawMarks(void)
  1329. {
  1330.     int i, fx, fy, w, h;
  1331.  
  1332.     for (i=0;i<AM_NUMMARKPOINTS;i++)
  1333.     {
  1334.         if (markpoints[i].x != -1)
  1335.         {
  1336.             //      w = SHORT(marknums[i]->width);
  1337.             //      h = SHORT(marknums[i]->height);
  1338.             w = 5; // because something's wrong with the wad, i guess
  1339.             h = 6; // because something's wrong with the wad, i guess
  1340.             fx = CXMTOF(markpoints[i].x);
  1341.             fy = CYMTOF(markpoints[i].y);
  1342.             if (fx >= f_x && fx <= f_w - w && fy >= f_y && fy <= f_h - h)
  1343.                 V_DrawPatch(fx, fy, FB, marknums[i]);
  1344.         }
  1345.     }
  1346.  
  1347. }
  1348.  
  1349. void AM_drawCrosshair(int color)
  1350. {
  1351.     fb[(f_w*(f_h+1))/2] = color; // single point for now
  1352.  
  1353. }
  1354.  
  1355. void AM_Drawer (void)
  1356. {
  1357.     if (!automapactive) return;
  1358.  
  1359.     /* Map On HeadUp Patch - CDE 98' */
  1360.     if(!maponhu)
  1361.         AM_clearFB(BACKGROUND);
  1362.  
  1363.     if (grid)
  1364.         AM_drawGrid(GRIDCOLORS);
  1365.     AM_drawWalls();
  1366.     AM_drawPlayers();
  1367.     if (cheating==2)
  1368.         AM_drawThings(THINGCOLORS, THINGRANGE);
  1369.     AM_drawCrosshair(XHAIRCOLORS);
  1370.  
  1371.     AM_drawMarks();
  1372.  
  1373.     V_MarkRect(f_x, f_y, f_w, f_h);
  1374.  
  1375. }
  1376.